package com.christ.society.service.utils;

import java.lang.reflect.Field;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.christ.society.bean.user.UserInfo;

public class ParamUtil {

    public static Map<String, Object> addParams(Map<String, Object> map,int start,int size) {
    	if(map == null){
    		map = new HashMap<String, Object>();
    	}
    	map.put("start",start);
    	map.put("size", size);
		return map;
	  }
    public static int toStart(int page,int pagesize) {
    	int start = 0;
		if(page > 1){
			start = pagesize * (page-1) - 1;
		}
		return start;
	}
    
    public static Map<String, Object> addParamsToPage(Map<String, Object> map,int page,int pagesize) {
    	if(map == null)
    		map = new HashMap<String,Object>();
    	map.put("start",toStart(page, pagesize));
    	map.put("size", pagesize);
		return map;
	  }

    public static Map<String,Object> hashParam(Object param,int page,int pagesize){
         Map<String,Object> map = new HashMap<String, Object>();
        Field [] fields =  param.getClass().getDeclaredFields();
        for (Field field : fields){
            field.setAccessible(true);
            try {
                map.put(field.getName(),field.get(param));
            }catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                 e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return addParams(map,page,pagesize);
    }

    public static void main(String [] args) {
        UserInfo lookParam = new UserInfo();
        lookParam.setId(1);
        lookParam.setUserName("sdsds");
      Map<String,Object> map =  hashParam(lookParam,1,20);
        System.out.println(map.size());
        System.out.println(map.toString());
    }

}
